//
//  BaseViewController.swift
//  DouYuZB
//
//  Created by wangpeng on 2017/5/7.
//  Copyright © 2017年 鼎商动力. All rights reserved.
//

import UIKit

class BaseViewController: UIViewController {
    
    //MARK: - 定义属性
    var contentsView :UIView?
    
    //MARK: - 懒加载
    fileprivate lazy var animImageView: UIImageView = {[unowned self] in
        let imageView = UIImageView(image: #imageLiteral(resourceName: "img_loading_1"))
        imageView.center = self.view.center
        imageView.animationImages = [#imageLiteral(resourceName: "img_loading_1"),#imageLiteral(resourceName: "img_loading_2")]
        imageView.animationDuration = 0.5
        imageView.animationRepeatCount = LONG_MAX
        imageView.autoresizingMask = [.flexibleTopMargin,.flexibleBottomMargin]
        return imageView
        }()
    
    //MARK: - 系统回调
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupUI()
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        
    }
}

extension BaseViewController{
    //设置UI界面
    func setupUI()  {
        //1.隐藏内容的Viwe
        contentsView?.isHidden = true
        //2.添加执行动画的ImageView
        self.view.addSubview(animImageView)
        //3.给animImageView 添加动画执行事件
        animImageView.startAnimating()
        //4.给view设置背景色
        view.backgroundColor = UIColor(r: 250, g: 250, b: 250)
    }
    
    
    /// 数据请求完成
    func loadDataFinish() {
        //1.结束动画
        animImageView.stopAnimating()
        //2.隐藏动画View
        animImageView.isHidden = true
        //3.让CollectionView显示出来
        contentsView?.isHidden = false
    }
}
